

#ifndef __CYC_BUF_H__
#define __CYC_BUF_H__

	#define CYC_BUF_SIZE               (128)               /* serial buffer in bytes (power 2) */
	#define CYC_BUF_MASK               (CYC_BUF_SIZE-1ul)  	/* buffer size mask */


	typedef struct __CYC_BUF_T {
		unsigned short wrIdx;
		unsigned short rdIdx;
		unsigned short rdIdxFix;
		unsigned short wrIdxFix;
		unsigned char  data[CYC_BUF_SIZE + 1];			//
	} CYC_BUF_T;

	#define CYC_BUF_RESET(CycBuf)      (CycBuf.rdIdx = CycBuf.wrIdx = 0)
	#define CYC_BUF_WR(CycBuf, dataIn) (CycBuf.data[CYC_BUF_MASK & CycBuf.wrIdx++] = (dataIn))
	#define CYC_BUF_RD(CycBuf)         (CycBuf.data[CYC_BUF_MASK & CycBuf.rdIdx++])   
	#define CYC_BUF_EMPTY(CycBuf)      (CycBuf.rdIdx == CycBuf.wrIdx)
	#define CYC_BUF_FULL(CycBuf)       ((CYC_BUF_MASK & CycBuf.rdIdx) == (CYC_BUF_MASK & (CycBuf.wrIdx+1)))
	#define CYC_BUF_COUNT(CycBuf)      (CYC_BUF_MASK & (CycBuf.wrIdx - CycBuf.rdIdx))
	#define CYC_BUF_FIXRD(CycBuf)		   (CycBuf.rdIdxFix = CycBuf.rdIdx)
	#define CYC_BUF_UNFIXRD(CycBuf)    (CycBuf.rdIdx = CycBuf.rdIdxFix)

  extern CYC_BUF_T sc16is7xx_txbuf[];
  extern CYC_BUF_T sc16is7xx_rxbuf[];

#endif

